package IteratorAndComposite.IteratorWaitess;

import IteratorAndComposite.IteratorInterfaces.Menu;
import IteratorAndComposite.entry.MenuItem;

import java.util.Iterator;

/**
 * @Author: pengzx
 * @Description:
 * @Date: 17:41 2017/9/19
 * @Modified by: 1.0
 */
public class Waitess {
    //还是使用了两个具体的类，需要修改一下
    Menu dinerMune;
    Menu pancakeHouseMenu;
    Menu cafeMenu;

    public Waitess(Menu dinerMune, Menu pancakeHouseMenu,Menu cafeMenu)
    {
        this.dinerMune = dinerMune;
        this.pancakeHouseMenu = pancakeHouseMenu;
        this.cafeMenu = cafeMenu;
    }

    public void printMenu(){
        Iterator pancakeHouseIterator = pancakeHouseMenu.createIterator();
        Iterator dinerIterator = dinerMune.createIterator();
        Iterator cafeIterator = cafeMenu.createIterator();
        System.out.println("输出菜单...");
        System.out.println("------------------------------");
        System.out.println("dinerMune->");
        printMenu(dinerIterator);
        System.out.println("------------------------------");
        System.out.println("pancakeHouseMenu->");
        printMenu(pancakeHouseIterator);
        System.out.println("------------------------------");
        System.out.println("cafeMenu->");
        printMenu(cafeIterator);
    }

    private void printMenu(Iterator iterator){
        while (iterator.hasNext()){
           MenuItem menuItem = (MenuItem) iterator.next();
            System.out.print(menuItem.getName()+",");
            System.out.print(menuItem.getDestription()+",");
            System.out.println(menuItem.getPrice());
        }
    }


}
